<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <meta charset="utf-8"/>
    <title>    TFC-Trotri Foundation Classes &raquo; \tfc\validator\Filter
</title>
    <meta name="author" content=""/>
    <meta name="description" content=""/>

            <link href="../css/template.css" rel="stylesheet" media="all"/>
    
            <!--[if lt IE 9]>
        
        <![endif]-->
        <script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script src="../js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
        <script src="../js/jquery.mousewheel.min.js" type="text/javascript"></script>
        <script src="../js/bootstrap.js" type="text/javascript"></script>
        <script src="../js/template.js" type="text/javascript"></script>
        <script src="../js/prettify/prettify.min.js" type="text/javascript"></script>
    
            <link rel="shortcut icon" href="../img/favicon.ico"/>
        <link rel="apple-touch-icon" href="../img/apple-touch-icon.png"/>
        <link rel="apple-touch-icon" sizes="72x72" href="../img/apple-touch-icon-72x72.png"/>
        <link rel="apple-touch-icon" sizes="114x114" href="../img/apple-touch-icon-114x114.png"/>
    </head>
<body>

        <div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container">
                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span> <span class="icon-bar"></span>
                    <span class="icon-bar"></span> </a>
                <a class="brand" href="http://www.trotri.com/">Trotri官网</a><a class="brand" href="../index.html">TFC-Trotri Foundation Classes</a>

                <div class="nav-collapse">
                    <ul class="nav">
                        <li class="dropdown">
                            <a href="#api" class="dropdown-toggle" data-toggle="dropdown">
                                API Documentation <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                                                    <li><a>Namespaces</a></li>
                                                                        <li><a href="../namespaces/tfc.html">tfc</a></li>
                                                                                                                                </ul>
                        </li>
                        <li class="dropdown" id="charts-menu">
                            <a href="#charts" class="dropdown-toggle" data-toggle="dropdown">
                                Charts <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="../graph_class.html">
                                        <i class="icon-list-alt"></i>&#160;Class hierarchy diagram
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="dropdown" id="reports-menu">
                            <a href="#reports" class="dropdown-toggle" data-toggle="dropdown">
                                Reports <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="../errors.html">
                                         
                                    </a>
                                </li>
                                <li>
                                    <a href="../markers.html">
                                        <i class="icon-list-alt"></i>&#160;Markers
                                    </a>
                                </li>
                                <li>
                                    <a href="../deprecated.html">
                                        <i class="icon-list-alt"></i>&#160;Deprecated
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="go_to_top">
            <a href="#___" style="color: inherit">Back to top&#160;&#160;<i class="icon-upload icon-white"></i></a>
        </div>
    </div>
    
    <div id="___" class="container">
        <noscript>
            <div class="alert alert-warning">
                Javascript is disabled; several features are only available if Javascript is enabled.
            </div>
        </noscript>

        
            <style>
        .deprecated h2 {
            text-decoration: line-through;
        }
    </style>
    <div class="row">
        <div class="span4">
                    <div class="btn-group view pull-right" data-toggle="buttons-radio">
        <button class="btn details" title="Show descriptions and method names"><i class="icon-list"></i></button>
        <button class="btn simple" title="Show only method names"><i class="icon-align-justify"></i></button>
    </div>
    <div class="btn-group visibility" data-toggle="buttons-checkbox">
        <button class="btn public active" title="Show public elements">Public</button>
        <button class="btn protected" title="Show protected elements">Protected</button>
        <button class="btn private" title="Show private elements">Private</button>
        <button class="btn inherited active" title="Show inherited elements">Inherited</button>
    </div>

        <ul class="side-nav nav nav-list">
        <li class="nav-header">
            <i class="icon-custom icon-method"></i> Methods
            <ul>
                                                                                                    <li class="method public">
        <a href="#method_run" title="run :: 运行验证处理类">
            <span class="description">运行验证处理类</span><pre>run</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_clean" title="clean :: 基于配置清理表单提交的数据
&lt;pre&gt;
一.清理规则：
$rules = array(
    &#039;user_loginname&#039; =&gt; &#039;trim&#039;,
    &#039;user_interest&#039; =&gt; array($foo, &#039;explode&#039;)
);
参数：
$attributes = array(
    &#039;user_loginname&#039; =&gt; &#039;  abcdefghi  &#039;,
    &#039;user_interest&#039; =&gt; &#039; 1, 2&#039;
);
结果：
$result = array(
    &#039;user_loginname&#039; =&gt; &#039;abcdefghi&#039;,
    &#039;user_interest&#039; =&gt; array(1, 2)
);">
            <span class="description">基于配置清理表单提交的数据
&lt;pre&gt;
一.清理规则：
$rules = array(
    &#039;user_loginname&#039; =&gt; &#039;trim&#039;,
    &#039;user_interest&#039; =&gt; array($foo, &#039;explode&#039;)
);
参数：
$attributes = array(
    &#039;user_loginname&#039; =&gt; &#039;  abcdefghi  &#039;,
    &#039;user_interest&#039; =&gt; &#039; 1, 2&#039;
);
结果：
$result = array(
    &#039;user_loginname&#039; =&gt; &#039;abcdefghi&#039;,
    &#039;user_interest&#039; =&gt; array(1, 2)
);</span><pre>clean</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_createValidator" title="createValidator :: 创建验证类">
            <span class="description">创建验证类</span><pre>createValidator</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_getValidator" title="getValidator :: 根据类名获取验证类">
            <span class="description">根据类名获取验证类</span><pre>getValidator</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_getErrors" title="getErrors :: 获取所有的错误信息">
            <span class="description">获取所有的错误信息</span><pre>getErrors</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_clearErrors" title="clearErrors :: 清除所有的错误信息">
            <span class="description">清除所有的错误信息</span><pre>clearErrors</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_getError" title="getError :: 通过键名获取错误信息">
            <span class="description">通过键名获取错误信息</span><pre>getError</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_addError" title="addError :: 添加一条错误信息">
            <span class="description">添加一条错误信息</span><pre>addError</pre>
        </a>
    </li>

                                                                                                        <li class="method public">
        <a href="#method_hasError" title="hasError :: 通过键名判断错误信息是否存在">
            <span class="description">通过键名判断错误信息是否存在</span><pre>hasError</pre>
        </a>
    </li>

                                                </ul>
        </li>
        <li class="nav-header protected">» Protected
            <ul>
                                                                                                                                                                                                                                                                                                                                                                                </ul>
        </li>
        <li class="nav-header private">» Private
            <ul>
                                                                                                                                                                                                                                                                                                                                                                                </ul>
        </li>
        <li class="nav-header">
            <i class="icon-custom icon-constant"></i> Constants
            <ul>
                            </ul>
        </li>
    </ul>


        </div>

        <div class="span8">
            <div class="element class">
                <h1>Filter</h1>
                <small style="display: block; text-align: right">
                                                        </small>
                <p class="short_description">Filter class file
数据验证类</p>
                <div class="details">
                    <div class="long_description">
                        <p>验证规则：</p>
<pre>
$rules = array(
    'user_loginname' => array(
        'MinLength' => array(6, '用户名长度%value%不能小于%option%个字符.'),
        'MaxLength' => array(12, '用户名长度%value%不能大于%option%个字符.')
    ),
    'user_password' => array(
        'tfc\\validator\\MinLengthValidator' => array(6, '密码长度%value%不能小于%option%个字符.'),
        'MaxLength' => array(12, '密码长度%value%不能大于%option%个字符.')
    ),
    'user_email' => array(
        'MaxLength' => array(50, '邮箱长度%value%不能大于%option%个字符.'),
        'Mail' => array(true, '邮箱%value%不符合规范.')
    ),
);

$params = array(
    'user_loginname' => 'abcdefghi',
    'user_password' => '1234',
    'user_email' => 'trotriyeahnet'
);

$filter = new Filter();
$result = $filter->run($rules, $params);
$errors = $filter->getErrors();
结果：
$errors = array(
    'user_password' => '密码长度1234不能小于6个字符.',
    'user_email' => array('邮箱长度trotriyeahnet...不能大于50个字符.', '邮箱iphperyeahnet...不符合规范.')
);
</pre>
                    </div>
                    <table class="table table-bordered">
                                                                                    <tr>
                                    <th>
                                        author
                                                                            </th>
                                    <td>
                                                                                    
                                                                                <p>宋欢 <a href="mailto:trotri@yeah.net">trotri@yeah.net</a></p>
                                    </td>
                                </tr>
                                                                                                                <tr>
                                    <th>
                                        version
                                                                            </th>
                                    <td>
                                                                                    
                                                                                <p>$Id: Filter.php 1 2013-03-29 16:48:06Z huan.song $</p>
                                    </td>
                                </tr>
                                                                                                                <tr>
                                    <th>
                                        package
                                                                            </th>
                                    <td>
                                                                                    
                                                                                <p>tfc.validator</p>
                                    </td>
                                </tr>
                                                                                                                <tr>
                                    <th>
                                        since
                                                                            </th>
                                    <td>
                                                                                    1.0
                                                                                
                                    </td>
                                </tr>
                                                                                                                                                                                                                                    </table>

                    <h3><i class="icon-custom icon-method"></i> Methods</h3>
                                                                <a id="method_run"></a>
                        <div class="element clickable method public  method_run" data-toggle="collapse" data-target=".method_run .collapse">
                            <h2>运行验证处理类</h2>
                            <pre>run(array $rules, array $attributes, boolean $required = true) : boolean</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    throws
                                                </th>
                                                <td>
                                                                                                                                                                        
                                                                                                                                                                        <p>如果验证规则或者验证数据不是数组，抛出异常</p>
                                                                                                                                                                        
                                                                                                                                                                        <p>如果字段验证规则不是数组，抛出异常</p>
                                                                                                                                                                        
                                                                                                                                                                        <p>如果键名在验证数据中不存在，抛出异常</p>
                                                                                                    </td>
                                            </tr>
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$rules</h4>
                                                <code>array</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$attributes</h4>
                                                <code>array</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$required</h4>
                                                <code>boolean</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code>boolean</code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_clean"></a>
                        <div class="element clickable method public  method_clean" data-toggle="collapse" data-target=".method_clean .collapse">
                            <h2>基于配置清理表单提交的数据
&lt;pre&gt;
一.清理规则：
$rules = array(
    &#039;user_loginname&#039; =&gt; &#039;trim&#039;,
    &#039;user_interest&#039; =&gt; array($foo, &#039;explode&#039;)
);
参数：
$attributes = array(
    &#039;user_loginname&#039; =&gt; &#039;  abcdefghi  &#039;,
    &#039;user_interest&#039; =&gt; &#039; 1, 2&#039;
);
结果：
$result = array(
    &#039;user_loginname&#039; =&gt; &#039;abcdefghi&#039;,
    &#039;user_interest&#039; =&gt; array(1, 2)
);</h2>
                            <pre>clean(array $rules, array $attributes) : array</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"><p>二.清理规则：
$rules = array(</p>
<pre><code>'user_password' =&gt; 'md5',
'user_interest' =&gt; array($foo, 'implode')</code></pre>
<p>);
参数：
$attributes = array(</p>
<pre><code>'user_password' =&gt; '  1234  ',
'user_interest' =&gt; array(1, 2)</code></pre>
<p>);
结果：
$result = array(</p>
<pre><code>'user_loginname' =&gt; '81dc9bdb52d04dc20036dbd8313ed055',
'user_interest' =&gt; '1,2'</code></pre>
<p>);
</pre></p></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$rules</h4>
                                                <code>array</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$attributes</h4>
                                                <code>array</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code>array</code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_createValidator"></a>
                        <div class="element clickable method public  method_createValidator" data-toggle="collapse" data-target=".method_createValidator .collapse">
                            <h2>创建验证类</h2>
                            <pre>createValidator(string $className, mixed $value, mixed $rule) : \tfc\validator\Validator</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    throws
                                                </th>
                                                <td>
                                                                                                                                                                        
                                                                                                                                                                        <p>如果Validator类不存在，抛出异常</p>
                                                                                                    </td>
                                            </tr>
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$className</h4>
                                                <code>string</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$value</h4>
                                                <code>mixed</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$rule</h4>
                                                <code>mixed</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code><a href="../classes/tfc.validator.Validator.html">\tfc\validator\Validator</a></code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_getValidator"></a>
                        <div class="element clickable method public  method_getValidator" data-toggle="collapse" data-target=".method_getValidator .collapse">
                            <h2>根据类名获取验证类</h2>
                            <pre>getValidator(string $className, mixed $value, mixed $option, string $message) : \tfc\validator\Validator</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    throws
                                                </th>
                                                <td>
                                                                                                                                                                        
                                                                                                                                                                        <p>如果获取的实例不是tfc\validator\Validator类的子类，抛出异常</p>
                                                                                                    </td>
                                            </tr>
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$className</h4>
                                                <code>string</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$value</h4>
                                                <code>mixed</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$option</h4>
                                                <code>mixed</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$message</h4>
                                                <code>string</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code><a href="../classes/tfc.validator.Validator.html">\tfc\validator\Validator</a></code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_getErrors"></a>
                        <div class="element clickable method public  method_getErrors" data-toggle="collapse" data-target=".method_getErrors .collapse">
                            <h2>获取所有的错误信息</h2>
                            <pre>getErrors(boolean $justOne = false) : array</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$justOne</h4>
                                                <code>boolean</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code>array</code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_clearErrors"></a>
                        <div class="element clickable method public  method_clearErrors" data-toggle="collapse" data-target=".method_clearErrors .collapse">
                            <h2>清除所有的错误信息</h2>
                            <pre>clearErrors() : \tfc\validator\Validator</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                    
                                                                            <h3>Response</h3>
                                        <code><a href="../classes/tfc.validator.Validator.html">\tfc\validator\Validator</a></code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_getError"></a>
                        <div class="element clickable method public  method_getError" data-toggle="collapse" data-target=".method_getError .collapse">
                            <h2>通过键名获取错误信息</h2>
                            <pre>getError(string|null $key = null, boolean $justOne = true) : mixed</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$key</h4>
                                                <code>string|null</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$justOne</h4>
                                                <code>boolean</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code>mixed</code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_addError"></a>
                        <div class="element clickable method public  method_addError" data-toggle="collapse" data-target=".method_addError .collapse">
                            <h2>添加一条错误信息</h2>
                            <pre>addError(string $key, string $value) : \tfc\validator\Validator</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$key</h4>
                                                <code>string</code><p></p>
                                            </div>
                                                                                    <div class="subelement argument">
                                                <h4>$value</h4>
                                                <code>string</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code><a href="../classes/tfc.validator.Validator.html">\tfc\validator\Validator</a></code><p></p>
                                                                    </div>
                            </div>
                        </div>
                                            <a id="method_hasError"></a>
                        <div class="element clickable method public  method_hasError" data-toggle="collapse" data-target=".method_hasError .collapse">
                            <h2>通过键名判断错误信息是否存在</h2>
                            <pre>hasError(string|null $key = null) : boolean</pre>
                            <div class="labels">
                                                                                                                                                                                            </div>
                            <div class="row collapse">
                                <div class="detail-description">
                                    <div class="long_description"></div>

                                    <table class="table">
                                                                                    <tr>
                                                <th>
                                                    
                                                </th>
                                                <td>
                                                                                                    </td>
                                            </tr>
                                                                            </table>

                                                                            <h3>Arguments</h3>
                                                                                    <div class="subelement argument">
                                                <h4>$key</h4>
                                                <code>string|null</code><p></p>
                                            </div>
                                                                            
                                                                            <h3>Response</h3>
                                        <code>boolean</code><p></p>
                                                                    </div>
                            </div>
                        </div>
                    
                    
                                                                <h3><i class="icon-custom icon-property"></i> Properties</h3>
                                                    <a id="property__errors"> </a>
                            <div class="element clickable property  protected property__errors" data-toggle="collapse" data-target=".property__errors .collapse">
                                <h2>寄存所有错误信息</h2>
                                <pre>_errors : array</pre>
                                <div class="labels">
                                                                                                        </div>
                                <div class="row collapse">
                                    <div class="detail-description">
                                        <div class="long_description"></div>

                                        <table class="table">
                                                                                            <tr>
                                                    <th>
                                                        var
                                                    </th>
                                                    <td>
                                                                                                                    <p>寄存所有错误信息</p>
                                                                                                            </td>
                                                </tr>
                                                                                            <tr>
                                                    <th>
                                                        
                                                    </th>
                                                    <td>
                                                                                                            </td>
                                                </tr>
                                                                                    </table>

                                                                                    <h3>Type(s)</h3>
                                            <code>array</code>
                                                                            </div>
                                </div>
                            </div>
                                                            </div>
            </div>
            <a id="\tfc\validator\Filter"></a>
            <ul class="breadcrumb">
                <li><a href="../index.html"><i class="icon-custom icon-class"></i></a></li>
                    
    
    <li><span class="divider">\</span><a href="../namespaces/tfc.validator.html">validator</a></li>

                <li class="active"><span class="divider">\</span><a href="../classes/tfc.validator.Filter.html">Filter</a></li>
            </ul>
        </div>
    </div>

    </div>

        <footer class="span12">
            Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by
            <a href="http://glyphicons.com/">Glyphicons</a>.<br/>
            Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor </a> and<br/>
            generated on Sat, 27 Dec 2014 06:16:37 +0000.<br/>
    </footer>
    </body>
</html>
